package me.lensfrex.trailblazer.api.v1.beans.responses.general;

import com.google.gson.annotations.SerializedName;

public class ResponseBase<T> {
    /**
     * 信息码
     */
    private int code;

    /**
     * 处理信息
     */
    @SerializedName("msg")
    private String message;

    private T data;

    /**
     * 构造一个基本响应
     * @param code 信息码
     * @param message 处理信息
     */
    public ResponseBase(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static<S> ResponseBase<S> success(S data) {
        return new ResponseBase<>(ResponseCode.SUCCESS, "success", data);
    }

    public static<S> ResponseBase<S> error(int responseCode, String message) {
        return new ResponseBase<>(responseCode, message, null);
    }
}